
# 文件操作类
class File:
    __fp = None
    __name = ''
    __path = ''
    __file = ''
    __mode = ''
    __encoding = ''

    def __init__(self, file, mode, encoding = 'utf8'):
        self.__file = file
        self.__mode = mode
        self.__encoding = encoding

    def open(self):
        self.__fp = open(file=self.__file, mode=self.__mode, encoding=self.__encoding)
        return self

    def readLines(self, isStrip = True, withClose = False):
        lines = []
        if isStrip:
            res = self.__fp.readlines()
            for item in res:
                lines.append(item.strip())
        else: lines = self.__fp.readlines()
        if withClose:
            self.close()
        return lines

    def readLine(self, isStrip = True):
        if isStrip: return self.__fp.readline().strip()
        return self.__fp.readline()

    def resRead(self):
        self.__fp.seek(0)

    def writeOneLine(self, text):
        self.__fp.write(text)
        return True

    def writeFiles(self, lines, withClose = False):
        for line in lines:
            self.__fp.write(line)
            self.__fp.write('\n')
        if withClose:
            self.close()

    def flush(self):
        self.__fp.flush()
        return self

    def close(self):
        self.__fp.close()
